﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UserDefineForm.control;
using UserDefineForm.formcomponent;
using UserDefineForm.dao.orm;
using UserDefineForm.dao.supplierform;
using System.IO;

namespace UserDefineForm
{
    public partial class SupplierFormGUI : Form
    {
        public ToolBox toolBox;
        public DesignPanel designPanel;
        public PropertiesPanelv2 propertiesPnl;

        private SupplierFormService formService;

        public SupplierFormGUI()
        {

            InitializeComponent();

            //testDAO();
            initControl();
            formService = new SupplierFormService(this);

           //formService.OpenForm(17);
        }

        public void reset()
        {
            designPanel.setBackGround(null);
            nameTxt.Text = "";
            designPanel.clearControl();
            designPanel.Refresh();
            propertiesPnl.setControl(null);
            propertiesPnl.Refresh();
            SystemFactory.setCurrentForm(new SupplierFormORM());
            this.Refresh();
        }

        private void testDAO()
        {
            ControlORM orm1 = new ControlORM();
            ControlDAO dao = SystemFactory.getControlDAO();

            orm1.Value = "keke";
            //orm1 = dao.getFormById(1);
            dao.insertControl(orm1);
        }


        private void initControl()
        {
            this.designPanel = new DesignPanel();
            propertiesPnl = new PropertiesPanelv2(designPanel);
            this.toolBox = new ToolBox(designPanel, propertiesPnl);
            
            this.SuspendLayout();

            this.toolBox.Dock = DockStyle.Top;
            this.propertiesPnl.Dock = DockStyle.Top;
            this.designPanel.Dock = DockStyle.Fill;

            this.leftPnl.Controls.Add(toolBox);
            this.rightPnl.Controls.Add(propertiesPnl);
            this.midPnl.Controls.Add(designPanel);

            this.ResumeLayout();
        }

        private void designRdBtn_CheckedChanged(object sender, EventArgs e)
        {
            if (designRdBtn.Checked)
            {
                designPanel.Mode = Modes.Design;
                toolBox.Enabled = true;
                propertiesPnl.Enabled = true;
            }
            else
            {
                designPanel.Mode = Modes.Run;
                toolBox.Enabled = false;
                propertiesPnl.Enabled = false;
            }
        }

        private void loadBackGroundBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog();
            fileDlg.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg";
            if (fileDlg.ShowDialog() == DialogResult.OK)
            {
                Image bgr = Image.FromFile(fileDlg.FileName);
                designPanel.setBackGround(bgr);
            }

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            formService.SaveCurrentForm();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenSupplierForm openForm = new OpenSupplierForm(formService);
            openForm.ShowDialog(this);
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            reset();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }




 
    }
}
